const app = getApp()
Page({
    data: {
        wxOpenId: '',
        jobList: [
            {name: '省区经理', value: 1},
            {name: '地区经理', value: 2},
            {name: '业务员', value: 3}
        ],
        productList: [
            {name: '黄金单品', value: 1, checked: false},
            {name: '普药', value: 2, checked: false},
        ],
        info: {
            gender: 0,
            realName: '',
            phone: '',
            investmentCapacity: '', // 出资能力
            expectOperateType: '', // 期望操作作品类型
            formerOperateType: '', // 原操作作品类型
            formerCompanyHonours: [{}, {}], // 原就职业and 辉煌
            formerPosition: '', // 原职位
            expectPosition: '', // 期望职位
            provinceId: '',
            cityId: '',
            destrictId: '',
            "expectProvince": null,
            "expectProvinceName": null,
            "expectCity": null,
            "expectCityName": null,
            "expectCountry": null,
            "expectCountryName": null,
            expectOperateAddress: [], // 地址组合
            formerOperateType: '', //原作品类型
            expectOperateType: '',  // 期望作品类型
        },
        formerPosition: '',
        expectPosition: '',
        formerOperateType: '',
        expectOperateType: '',
        shareCode: '',//邀请码
    },
    onLoad () {
        this.setData({wxOpenId: wx.getStorageSync('wxOpenId')})
        this.getData();
        this.getShareCode();
    },
    doData(strs) {
        const {productList} = this.data
        let arr = strs.split(',')
        let str = ''
        productList.forEach(r => {
            if (arr.includes(r.value + '')) {
                if (!str) {
                    str += r.name
                } else {
                    str += '/' + r.name
                }
            }
        })
        console.log(str)
        return str
    },
    getData() {
        app.getRequest('/user/getUserInfo', {wxOpenId: this.data.wxOpenId}).then(res => {
            if (res.code == 0) {
                let info = res.data
                const {jobList, productList} = this.data
                let formerPosition, expectPosition, expectOperateType, formerOperateType
                formerPosition = info.formerPosition && jobList.filter(r => r.value == info.formerPosition)[0].name || ''
                expectPosition = info.expectPosition && jobList.filter(r => r.value == info.expectPosition)[0].name || ''
                formerOperateType = info.formerOperateType && this.doData(info.formerOperateType) || ''
                expectOperateType = info.expectOperateType && this.doData(info.expectOperateType) || ''
                this.setData({
                    info,
                    formerPosition,
                    expectPosition,
                    formerOperateType,
                    expectOperateType
                })
            }
        })
    },
    editer() {
        wx.redirectTo({url:"/pages/info/info"})
    },
    /* 获取分享邀请码 */
    getShareCode () {
        app.getRequest('/user/createCode', { wxOpenId:this.data.wxOpenId }).then( res=> {
            if(res.code == 0){
                this.setData({ shareCode:res.data })
            }else{
                app.dialogJs.tip(res.message)
            }
        })
    },
    /**用户点击右上角分享*/
    onShareAppMessage: function () {
        return {
            title: "加入渡头网",
            path: "/pages/index/index?shareCode="+ this.data.shareCode,
            imageUrl:'/images/index/code.png'
        }
    }
})
